<?php
/*! \brief
 * This is WFExitCode class
 * This class is maintain all the exit code of php CLI via interface_request.php
 * EX : php /path/to/interface.php <<file_interface>> <= execute this CLI will return exit code.
 * Important:
 * Exit statuses should be in the range 0 to 254, 
 * the exit status 255 is reserved by PHP and shall not be used.
 *\author William Su
 */
require_once dirname(__FILE__).'/ExitCode.abstract.php';
class WFExitCode extends AExitCode
{
    const ERROR_INIT_WIDGET_POOL_DB_SCHEMA = 100;
    const ERROR_SYN_MODXMLTODB = 110;
    const ERROR_SYN_MODXMLTODB_BYMODULENAME = 111;
    const ERROR_DELETE_MODXMLTODB_BYMODULENAME = 112;
    const ERROR_SYN_COMPONENTXMLTODB = 113;
    const ERROR_EXEC_DB_UPDATE_FILTER = 120;
    const ERROR_TURNONOFF_MOD_CATEGORY = 130;
    const ERROR_DELETE_USER_BY_ACCOUNT = 140;
    
    
    const ERROR_INIT_WIDGET_FRAMEWORK_DB_SCHEMA = 210;
    const ERROR_UPGRADE_WIDGET_FRAMEWORK = 220;
    public function __construct($objFramework){
        parent::__construct($objFramework);
        self::$instance['ExitCodeMsg'][self::ERROR_INIT_WIDGET_POOL_DB_SCHEMA] = 'Error init initWidgetPoolDBSchema!';
        self::$instance['ExitCodeMsg'][self::ERROR_SYN_MODXMLTODB] = 'Error synWidgetXMLToDB!';
        self::$instance['ExitCodeMsg'][self::ERROR_SYN_MODXMLTODB_BYMODULENAME] = 'Error synModXMLToDBByModuleName!';
        self::$instance['ExitCodeMsg'][self::ERROR_DELETE_MODXMLTODB_BYMODULENAME] = 'Error deleteModXMLToDBMyModuleName!';
        self::$instance['ExitCodeMsg'][self::ERROR_SYN_COMPONENTXMLTODB] = 'Error synWidgetComponentXMLToDB!';
        self::$instance['ExitCodeMsg'][self::ERROR_EXEC_DB_UPDATE_FILTER] = 'Error execDBUpdateFilter!';
        self::$instance['ExitCodeMsg'][self::ERROR_TURNONOFF_MOD_CATEGORY] = 'Error turnOffModCategory!';
        self::$instance['ExitCodeMsg'][self::ERROR_DELETE_USER_BY_ACCOUNT] = 'Error deleteUserByAccount!';

        
        self::$instance['ExitCodeMsg'][self::ERROR_INIT_WIDGET_FRAMEWORK_DB_SCHEMA] = 'Error init initWFDBSchema!';
        self::$instance['ExitCodeMsg'][self::ERROR_UPGRADE_WIDGET_FRAMEWORK] = 'Error upgrade Widget Framework!';
    }
    protected function getMsgByFileInterface($file_interface){
        switch($file_interface){
            case 'initWidgetPoolDBSchema.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpInitWidgetPoolDBSchema();
            break;
            case 'synWidgetXMLToDB.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpSynWidgetXMLToDB();
            break;
            case 'synWidgetComponentXMLToDB.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpSynWidgetComponentXMLToDB();
            break;
            case 'execDBUpdateFilter.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpExecDBUpdateFilter();
            break;
            case 'turnOnWidgetOfCategoryByVersion.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpTurnOnWidgetOfCategoryByVersion();
            break;
            case 'turnOffWidgetOfCategoryByVersion.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpTurnOffWidgetOfCategoryByVersion();
            break;
            case 'deleteWidgetFromDBByWidgetName.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpDeleteWidgetFromDBByWidgetName();
            break;
            case 'synWidgetXMLToDBByWidgetName.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpSynWidgetXMLToDBByWidgetName();
            break;
            case 'deleteUserByAccount.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpDeleteUserByAccount();
            break;
            
            case 'initWFDBSchema.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpInitWFDBSchema();
            break;
            case 'upgradeWF.php':
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpUpgradeWF();
            break;
            case 'mydefault': //attention : must have this case
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getHelpInterfaceRequest();
            break;
        }
        return $msg;
    }
    protected function getMsgByCode($intCode){
        $msg = '';
        switch($intCode){
            case self::ERROR_INIT_WIDGET_POOL_DB_SCHEMA:
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getMsgErrorInitWidgetPoolDbSchema();
            break;
            
            
            case self::ERROR_UPGRADE_WIDGET_FRAMEWORK:
                $msg = $this->objFramework->getWidgetFactory()->getInterface()->getMsgErrorUpgradeWF();
            break;
            case 255:
                $msg = "unknown system error";
            break;
            default:
                if(isset(self::$instance['ExitCodeMsg'][$intCode])){
                    $msg = self::$instance['ExitCodeMsg'][$intCode];
                }
                if($intCode && !$msg){ // because synServerListType.php doesn't return Exit code
                    $strMsg = __CLASS__.'::'.__FUNCTION__.'()=>Can\'t find message for exit code:['.$intCode.']';
                    throw new WFConfigExitCodeException($strMsg);
                }
            break;
        }
        return $msg;
    }
}